<template>
	<Modal v-model="modal"  title="更新备注" @on-ok="ok('form')"  :loading="loading">
		<IForm :model="form" ref="form" :rules="formRule">
			<FormItem prop="remark" label="备注名" >
	            <IInput v-model="form.remark" size="large" placeholder="请填写微信名,同步微信公众号" />
	        </FormItem>
		</IForm>
	</Modal>
</template>
<script>
	import {Button,Modal,Form,Input} from 'iview';
	export default{
		props :{
            callback:{
                type: Function,
                required : true,
            },
        },
		components:{
            Modal,
            'IInput' : Input,
			'IForm' : Form,
			'FormItem' : Form.Item,
			'IButton' : Button,
        },
        data(){
        	return {
        		modal : false,
        		loading : true,
        		form:{
        			id : 0,
        			remark:'',
        		},
        		formRule : {
	                remark: [
	                    { required: true, message: '请填写备注名', trigger: 'blur' },
	                ],
	            },
        	}
        },
        methods:{
        	changeLoading(){
	            this.loading = false;
	            this.$nextTick(() => {
	              this.loading = true;
	            });
	        },
        	ok(name){
        		this.$refs[name].validate(valid => {
        			if (!valid) {this.changeLoading();return false;}
        			this.Axios.Wechat.Manager.User.UpdateRemark(this.form)
		            .then(res =>{
		            	this.changeLoading();
		            	if(!res) return false;
		            	this.modal = false;
		            	this.callback();
		            })
        		})
        	},
        },
        watch:{
        	modal:function(newValue){
        		if(!newValue){
        			this.$refs['form'].resetFields();
        		}
        	}
        }
	}
</script>